<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
  <!--<script src="http://{$Think.config.google_map_url}" async="async"></script>-->
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

</head>
<body>
<div style="margin-top: 20px;">
</div>




<form class="layui-form" id="admin">

  <div class="layui-form-item " id="shangpin">
    <label class="layui-form-label">商品名称</label>
    <div class="layui-input-inline" style="width: 500px">
      <input name="goods_name"  value="{$aa.goods_name}" placeholder="请输入商品名称" autocomplete="off" class="layui-input"  type="text">
    </div>
  </div>

  <div class="layui-form-item " id="">
    <label class="layui-form-label">商品英文名称</label>
    <div class="layui-input-inline" style="width: 500px">
      <input name="goods_englishname"  value='{$aa.goods_englishname}' placeholder="请输入商品名称" autocomplete="off" class="layui-input"  type="text">
    </div>
  </div>

  <div class="layui-form-item " >
    <label class="layui-form-label">标签</label>
    <div class="layui-input-inline" style="position: relative;z-index: 10000;width: 400px">
      <select  id="trip"  lay-filter="addtrips"   lay-verify="required" lay-search>
        <option value="999999">全部</option>
        <?php foreach($aa->tag() as $vo){
       ?>
        <option value="{$vo.tag_id}">{$vo.tag_name}</option>


      <?php  }?>

      </select>
    </div>
    <span id="addtrips" data-name="全部" data-id="999999" class="layui-btn layui-btn-danger layui-btn-sm" style="margin-top: 4px">添加</span>
  </div>



  <div class="layui-form-item">
    <label class="layui-form-label">已选标签</label>
    <div class="layui-input-inline" style="width: 500px" id="tripnames">


      <?php
      $tag_id= explode(',',$aa['tag_id']);
       $l=count($tag_id);

        for ($i=0;$i<$l;$i++){

            foreach($aa->tag() as $v){
      if($tag_id[$i]==$v['tag_id']){
      ?>
      <span class="layui-btn layui-btn-sm layui-btn-normal deltripspan" data-id="{$v['tag_id']}" style="margin: 5px 10px">{$v['tag_name']}<i class="layui-icon"></i></span>

      <?php
                }
                }
      }
?>
      <input name="tag_id" id="tripids"  value="{$aa.tag_id}"  type="hidden">



    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">选择类型</label>
    <div class="layui-input-inline">
      <input type="radio"  lay-filter="poitype"  name="relation_type" value="1" <?php if($aa['relation_type']==1){ ?>checked<?php }?>  title="行程" >
      <input type="radio"  lay-filter="poitype"  name="relation_type" value="2" <?php if($aa['relation_type']==2){ ?>checked<?php }?> title="POI" >
    </div>
  </div>


  <div class="layui-form-item " id="zhekou" style="position: relative ;z-index: 100">
    <label class="layui-form-label">选择景区</label>
    <div class="layui-input-inline" style="width: 450px">
      <!--<input name="xp"  id="xp" value="" placeholder="请输入" autocomplete="off" list="list" class="layui-input"  type="text">-->
      <select    name="goods_location" id="list" lay-filter="addg"  lay-search>
        <!--<option  value="">&#45;&#45;请选择&#45;&#45;</option>-->
          <?php if($aa['relation_type']==1){
        $name=$g->trip();
          }else if($aa['relation_type']==2){
          $name=$g->poi();
          }?>
          {volist name='name' id='v'}

          <option <?php if($v['id']==$aa['relation_type']){ ?>checked<?php }?>  value="{$v.id}">{$v.name}</option>
          {/volist}



          {///volist name='aa' id='vo'}
        <!--<option  value="{//$vo.id}">{//$vo.name}</option>-->
        {///volist}
      </select>
    </div>
  </div>



  <div class="layui-form-item">
    <label class="layui-form-label">商品价格</label>
    <div class="layui-input-inline" style="position: relative;width: 500px">
      <input name="goods_price"  value="{$aa.goods_price}"   lay-verify="required" placeholder="请输入商品价格" autocomplete="off" class="layui-input" type="text">
      <div id="addressbox"></div>
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">商品数量</label>
    <div class="layui-input-inline" style="position: relative;width: 500px">
      <input name="goods_num"  value="{$aa.goods_num}"   lay-verify="required" placeholder="请输入商品数量" autocomplete="off" class="layui-input" type="text">
      <!--<div id="addressbox"></div>-->
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">携带儿童数</label>
    <div class="layui-input-inline" style="position: relative;width: 500px">
      <input name="carrying_children"  value="{$aa.carrying_children}"   lay-verify="required" placeholder="请输入商品数量" autocomplete="off" class="layui-input" type="text">
      <!--<div id="addressbox"></div>-->
    </div>
  </div>


  <div class="layui-form-item " id="" style="position: relative ;z-index: 99">
    <label class="layui-form-label">选择状态</label>
    <div class="layui-input-inline" style="width: 450px ;z-index: 9999">

      <select   id="zhuangtai" lay-filter="zhuang"  name="goods_status"   lay-search>


          <option  <?php if($aa['goods_status']==1){ ?>checked<?php }?>   value="1">售卖中</option>
         <option <?php if($aa['goods_status']==2){ ?>checked<?php }?> value="2">未售卖</option>
       <option <?php if($aa['goods_status']==3){ ?>checked<?php }?> value="3">已售罄</option>

      </select>
    </div>
  </div>



  <div class="layui-form-item layui-form-text" style="position: relative ;z-index: 98">
    <label class="layui-form-label">简介</label>
    <div class="layui-input-block" style="max-width:500px;">
      <textarea placeholder="请输入内容"  class="layui-textarea" id="jieshao" name="goods_introduce">{$aa.goods_introduce}</textarea>
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">英文介绍</label>
    <div class="layui-input-block" style="max-width:500px;">
      <textarea placeholder="请输入内容"  class="layui-textarea" id="jieshao2" name="goods_enintroduce">{$aa.goods_enintroduce}</textarea>
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">用时参考</label>
    <div class="layui-input-block" style="max-width:500px;">
      <textarea placeholder="请输入内容"  class="layui-textarea" id="yongshi" name="goods_usetime">{$aa.goods_usetime}</textarea>
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">费用包含</label>
    <div class="layui-input-block" style="max-width:500px;">
      <textarea placeholder="请输入内容"  class="layui-textarea" id="baohan" name="price_include">{$aa.price_include}</textarea>
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">费用不含</label>
    <div class="layui-input-block" style="max-width:500px;">
      <textarea placeholder="请输入内容"  class="layui-textarea" id="buhan" name="price_noinclude">{$aa.price_noinclude}</textarea>
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">注意事项</label>
    <div class="layui-input-block" style="max-width:500px;">
      <textarea placeholder="请输入内容"  class="layui-textarea" id="zhuyi" name="goods_careful">{$aa.goods_careful}</textarea>
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">退改规则</label>
    <div class="layui-input-block" style="max-width:500px;">
      <textarea placeholder="请输入内容"  class="layui-textarea" id="tuigai" name="goods_retreating">{$aa.goods_retreating}</textarea>
    </div>
  </div>

  <div class="layui-form-item" style="margin:0 110px ">
    <div class="layui-upload">
      <button type="button" class="layui-btn" id="upload1">图片上传（格式：jpg,png,gif,jpeg）                                                                                      </button>
      <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
        预览图：
        <div class="layui-upload-list" id="seeupload1">
          {notempty name='$aa.goods_image'}
          <?php

                    $img=explode(',',$aa['goods_image'] );?>
          <span class="uploadimgbox"><img class="layui-upload-img" src="{$img['1']}"><i class="layui-icon">&#x1006;</i></span>





          {/notempty}

          {volist name="$thumb" id="vo"}
          {if !empty($vo)}
          <span class="uploadimgbox"><img class="layui-upload-img" src="{$vo}"><i class="layui-icon">&#x1006;</i></span>
          {/if}
          {/volist}
        </div>
      </blockquote>
    </div>


    <input id="upload-thumb1" type="hidden" name="goods_image" value="{notempty name='$aa.goods_image'}{$aa.goods_image}{/notempty}{notempty name='$menu'}{$menu['thumb']}{/notempty}">
  </div>

  <!--<div class="layui-form-item">-->
    <!--<label class="layui-form-label">选择文件</label>-->
    <!--<div class="layui-input-inline">-->
      <!--<button type="button" class="layui-btn" id="uploadfile"><i class="layui-icon"></i><span id="uploadname">{if empty($menu['fileid'])||$menu['fileid']<1}上传文件{else}更改文件{/if}</span>（格式：PDF或者WORD）</button>-->
    <!--</div>-->
    <!--<input name="fileid" id="fileid" value="{notempty name='$menu'}{$menu.fileid}{/notempty}" placeholder="请输入" autocomplete="off" class="layui-input" type="hidden">-->
  <!--</div>-->

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="admin">确认复制</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>

</form>

<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
    });
</script>
<!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>

<script>
  //视频上传
  // layui.use('upload', function(){
  //     var upload = layui.upload;
  //     //执行实例
  //     upload.render({
  //         elem: '#uploadfile'
  //         ,url: "{:url('common/upload')}"
  //         ,accept: 'video', //普通文件
  //         'size':'0'
  //         ,done: function(res){
  //             if(res.code == 2) {
  //                 layer.msg("文件上传成功");
  //                 $("#uploadname").html("更改文件");
  //                 $("#fileid").val(res.id);
  //             } else {
  //                 layer.msg(res.msg);
  //             }
  //         }
  //     });
  //
  //
  // });


  //图片上传
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        upload.render({
            elem: '#upload1'
            ,url: "{:url('common/upload')}"
            ,multiple: true
            ,accept:"images"
            ,size:"50000"
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    $('#seeupload1').append('<span class="uploadimgbox"><img class="layui-upload-img" src="'+res.src+'"><i class="layui-icon">&#x1006;</i></span>');
                    $('#upload-thumb1').val($('#upload-thumb1').val()+","+res.src);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                //演示失败状态，并实现重传
                layer.closeAll('loading');
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function () {
                layer.load(2);
            }
        });

        upload.render({
            elem: '#upload2'
            ,url: "{:url('common/upload')}"
            ,multiple: true
            ,accept:"images"
            ,size:"50000"
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    $('#seeupload2').append('<span class="uploadimgbox"><img class="layui-upload-img" src="'+res.src+'"><i class="layui-icon">&#x1006;</i></span>');
                    $('#upload-thumb2').val($('#upload-thumb2').val()+","+res.src);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                //演示失败状态，并实现重传
                layer.closeAll('loading');
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function () {
                layer.load(2);
            }
        });

        upload.render({
            elem: '#upload3'
            ,url: "{:url('common/upload')}"
            ,multiple: true
            ,accept:"images"
            ,size:"50000"
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    $('#seeupload3').append('<span class="uploadimgbox"><img class="layui-upload-img" src="'+res.src+'"><i class="layui-icon">&#x1006;</i></span>');
                    $('#upload-thumb3').val($('#upload-thumb3').val()+","+res.src);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                //演示失败状态，并实现重传
                layer.closeAll('loading');
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function () {
                layer.load(2);
            }
        });

        upload.render({
            elem: '#upload4'
            ,url: "{:url('common/upload')}"
            ,multiple: true
            ,accept:"images"
            ,size:"50000"
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    $('#seeupload4').append('<span class="uploadimgbox"><img class="layui-upload-img" src="'+res.src+'"><i class="layui-icon">&#x1006;</i></span>');
                    $('#upload-thumb4').val($('#upload-thumb4').val()+","+res.src);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                //演示失败状态，并实现重传
                layer.closeAll('loading');
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function () {
                layer.load(2);
            }
        });

        upload.render({
            elem: '#upload5'
            ,url: "{:url('common/upload')}"
            ,multiple: true
            ,accept:"images"
            ,size:"50000"
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    $('#seeupload5').append('<span class="uploadimgbox"><img class="layui-upload-img" src="'+res.src+'"><i class="layui-icon">&#x1006;</i></span>');
                    $('#upload-thumb5').val($('#upload-thumb5').val()+","+res.src);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                //演示失败状态，并实现重传
                layer.closeAll('loading');
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function () {
                layer.load(2);
            }
        });

        upload.render({
            elem: '#upload6'
            ,url: "{:url('common/upload')}"
            ,multiple: true
            ,accept:"images"
            ,size:"50000"
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    $('#seeupload6').append('<span class="uploadimgbox"><img class="layui-upload-img" src="'+res.src+'"><i class="layui-icon">&#x1006;</i></span>');
                    $('#upload-thumb6').val($('#upload-thumb6').val()+","+res.src);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                //演示失败状态，并实现重传
                layer.closeAll('loading');
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function () {
                layer.load(2);
            }
        });
    });
    $("#seeupload1").on("click",".layui-icon",function(){
        $(this).parent().remove();
        thumb("seeupload1",1);
    });

    $("#seeupload2").on("click",".layui-icon",function(){
        $(this).parent().remove();
        thumb("seeupload2",2);
    });

    $("#seeupload3").on("click",".layui-icon",function(){
        $(this).parent().remove();
        thumb("seeupload3",3);
    });

    $("#seeupload4").on("click",".layui-icon",function(){
        $(this).parent().remove();
        thumb("seeupload4",4);
    });

    $("#seeupload5").on("click",".layui-icon",function(){
        $(this).parent().remove();
        thumb("seeupload5",5);
    });

    $("#seeupload6").on("click",".layui-icon",function(){
        $(this).parent().remove();
        thumb("seeupload6",6);
    });

    function thumb(obj,n){
        var thumbs="";
        $("#"+obj).find("img").each(function(){
            var url=$(this).attr("src");
            thumbs+=","+url;
        });
        $("#upload-thumb"+n).val(thumbs);
    }

</script>




<script>

    var ue0 = UE.getEditor('jieshao');
    var jieshao2 = UE.getEditor('jieshao2');
    var yongshi = UE.getEditor('yongshi');
    var baohan = UE.getEditor('baohan');
    var buhan = UE.getEditor('buhan');
    var zhuyi = UE.getEditor('zhuyi');
    var tuigai = UE.getEditor('tuigai');


    function muban(t){
        var op=""
            op+=" <option  value=''>--请选择--</option>"
        $.each(t,function (i,v) {
            op+="<option value='"+v.id+"'>"+v.name+"</option>"
        })
        return op;
    }

  layui.use(['layer', 'form','laydate','layedit'], function() {
      // var laydate = layui.laydate;
    var layer = layui.layer,
            $ = layui.jquery,
        laydate= layui.laydate,
            form = layui.form;


    $(window).on('load', function() {

        form.on('radio(poitype)', function(data){
            var val= $(this).val();
            $.post("{:url('addgoods')}",{'id':val},function (date) {

                var data =eval(date)
              $('#list option').remove();
              $('#list').append(muban(data));
                 // console.log( )

                form.render('select');
            })


        })


        $('#queding').click(function () {
           var id= $(this).attr("data-id");
            console.log(id)

        })





        form.on('select(addg)', function(data){
            var id=data.value;
           var sid= $('input[name="relation_type"]:checked').val();
          // console.log($id)
           $.post("{:url('xiala')}",{'sid':sid,'id':id},function (date) {
               var date=eval(date)

               if (date[0].hasOwnProperty('introduction') && date[0]['introduction']!==null){
                   ue0.setContent(date[0]['introduction']);
               }
               if (date[0].hasOwnProperty('price')  && date[0]['price']!==null){
                   baohan.setContent(date[0]['price']);
               }
               if (date[0].hasOwnProperty('priceno')  && date[0]['priceno']!==null){
                   buhan.setContent(date[0]['priceno']);
               }
               if (date[0].hasOwnProperty('eng_introduce')  && date[0]['eng_introduce']!==null){
                   jieshao2.setContent(date[0]['eng_introduce']);//英文简介
               }
               if (date[0].hasOwnProperty('introduce')  && date[0]['introduce']!==null){
                   ue0.setContent(date[0]['introduce']);
               }

               if (date[0].hasOwnProperty('careful')  && date[0]['careful']!==null){
                   zhuyi.setContent(date[0]['careful']);
               }
               if (date[0].hasOwnProperty('back')  && date[0]['back']!==null){
                   tuigai.setContent(date[0]['back']);

               }


           });
        });



      function fuzhi($t){
          console.log($t)
          $.each($t ,function (i,v) {


              // console.log(v.introduction)

              // var ue0 = UE.getEditor('jieshao');
              // ue0.addListener('ready', function (editor) {
              //     console.log(v.introduction)
              //     // ue.setContent(json.Body.GoodDescription);
              //     ue0.setContent(v.introduction);
              // });


          })



      }

        //商品范围选择下拉添加事件
        //商品范围选择下拉添加事件
        form.on('select(addtrips)', function(data){
            var tripid=data.value;
            $("#addtrips").attr("data-id",tripid);
        });

        $("#addtrips").on("click",function () {
            var tripid= $("#addtrips").attr("data-id");
            var tripids=$("#tripids").val();
            var ids=tripids.split(",");

            if (tripid==999999){
                tripids=999999;
                var tripspan='<span class="layui-btn layui-btn-sm layui-btn-normal deltripspan" data-id="999999" style="margin: 5px 10px">全部<i class="layui-icon"></i></span>';
                $("#tripnames").html(tripspan);
            }else{

                for(var i=0 ; i < ids.length; i++){
                    if(tripid==ids[i]){
                        layer.msg("不能重复添加商品");
                        return false;
                    }
                    if(ids[i]==999999){
                        tripids=999999;
                        var tripspan='<span class="layui-btn layui-btn-sm layui-btn-normal deltripspan" data-id="999999" style="margin: 5px 10px">全部<i class="layui-icon"></i></span>';
                        $("#tripnames").html(tripspan);
                        $("#tripids").val(tripids);
                        return false;
                    }
                }
                var tripname="";
                $("#trip").find("option").each(function () {
                    if($(this).val()==tripid){
                        tripname=$(this).html();
                    }
                });

                var tripspan='<span class="layui-btn layui-btn-sm layui-btn-normal deltripspan" data-id="'+tripid+'" style="margin: 5px 10px">'+tripname+'<i class="layui-icon"></i></span>';

                if(!tripids){
                    tripids+=tripid;
                }else{
                    tripids+=','+tripid;
                }
                $("#tripnames").append(tripspan);
            }



            $("#tripids").val(tripids);
        })






        $(document).on("click",'.deltripspan',function () {
            var dataid=$(this).attr("data-id");
            var tripids=$("#tripids").val();
            var ids=tripids.split(",");
            var newid="";
            for(var i=0 ; i < ids.length; i++){
                if(ids[i]&&dataid!=ids[i]){
                    if(!newid){
                        newid+=ids[i];
                    }else{
                        newid+=","+ids[i];
                    }
                }
            }
            $("#tripids").val(newid);
            $(this).remove();
        })



      form.on('submit(admin)', function(data) {

        $.ajax({
          url:"{:url('admin/goods/copy')}",
          data:$('#admin').serialize(),
          type:'post',
          async: false,
          success:function(res) {
            layer.msg(res.msg);
            if(res.code == 1) {
              setTimeout(function(){
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
              },1500)
            }
          }
        })
        return false;
      });
    });
  });
</script>

<!-- 实例化编辑器 -->
<script type="text/javascript">


</script>
</body>
</html>
